window.onload = function() {
    let username = document.getElementById("username")
    let password = document.getElementById("password")
    console.log(username.value)
    username.addEventListener("input", (e) => {
            console.log(e.target.value)
        })
        // let c1 = document.getElementById("c1")
        // let c2 = document.getElementById("c2")
        // c1.addEventListener("change",(e)=>{
        //     console.log(e.target.checked)
        // })
        // c2.addEventListener("change",(e)=>{
        //     console.log(e.target.checked)
        // })
        // let city = document.querySelector("#city")
        // console.log(city.value)
        // city.addEventListener("change",(e)=>{
        //     console.log(e.target.value)
        // })
    let btn = document.querySelector("button")
    btn.addEventListener("click", (e) => {
        // e.preventDefault()
        let name = username.value
        let passd = password.value
            // let xhr = new XMLHttpRequest()
            // xhr.open("GET", "http://172.19.11.61:8080/login" + "?username=" + name + '&password=' + passd, true)
            // xhr.onreadystatechange = function() {
            //     if (xhr.readyState === 4 && xhr.status === 200) {
            //         console.log("请求成功")
            //     }
            // }

        // xhr.send()
        // if (xhr.readyState === 4 && xhr.status === 200) {
        //     console.log("请求成功")
        // }

        let promise = new Promise((resolve, reject) => {
            let xhr = new XMLHttpRequest()
            xhr.open("GET", "http://172.19.14.60:8080/login" + "?username=" + name + '&password=' + passd, true)
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log("请求成功")
                    resolve(xhr.responseText)
                }
            }

            xhr.send()
                // let success = true
                // if(success){
                //     resolve()
                // }else{
                //     reject()
                // }
            setTimeout(() => {
                console.log("等待2秒")
                resolve("输出成功")
            }, 2000)
        })
        promise.then((e) => {
            console.log(e)
            console.log("成功")
        }).catch(() => {
            console.log("失败")
        }).finally(() => {
            console.log("成功失败都会执行")
        })
    })
}